home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / misc / request2.03.lha / Request2.03 / Request.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  8.0 KB  |  277 lines

  1. /*
  2.  *  Request.c - open an "rtEZRequestTags()" from script files
  3.  *
  4.  *  PUBLIC DOMAIN
  5.  *
  6.  *  by Stefan Sticht
  7.  *
  8.  *  V1.00             Stefan Sticht initial release
  9.  *  V1.01             Stefan Sticht using cres.o for residentability
  10.  *  V1.02 08 Sep 1991 Stefan Sticht added options "defpubscreen", "frontpubscreen"
  11.  *                                  renamed option "screen" in "pubscreen"
  12.  *  V1.03 16 Sep 1991 Stefan Sticht removed error lockfrontpubscr()
  13.  *  V1.04 03 Apr 1992 Stefan Sticht changed version string
  14.  *  V2.00 13 Jan 1994 Goncalves Georges changed version string and replaced
  15.  *                                      EasyRequest() by rtEZRequestTags()
  16.  *                                      which is faster, user friendly and
  17.  *                                      allows underscores, text centering,
  18.  *                                      default response. Size increased to
  19.  *                                      3528 bytes ( was 2404 ).
  20.  *
  21.  *  V2.01 12 Mar 1994 Goncalves Georges Recompiled with version 6.51 of
  22.  *                                      compiler with optimisation on. Size
  23.  *                                      reduced and is smaller than the
  24.  *                                      original ( 2404 ). Now 1935 bytes!
  25.  *
  26.  *  V2.02 05 Apr 1994 Goncalves Georges Removed a big error! an added a
  27.  *                                      NoDefault option to get rid of the
  28.  *                                      default gadget. Reduced again the
  29.  *                                      size ( 1912 bytes! ).
  30.  *
  31.  *  V2.03 10 Nov 1994 Goncalves Georges Added a FLASH option to flash screen
  32.  *                                      when requester appears. Added some
  33.  *                                      equivalents for args template.
  34.  *
  35.  *
  36.  * Use SAS/C 6.0 minimum to compile (or adapt the MakeFile). this version
  37.  * was compiled with SAS/C 6.51
  38.  *
  39.  */
  40.  
  41. #include "Includes.h"
  42.  
  43. //[ "The main() function..."
  44. struct Screen *lockfrontpubscr(void);
  45.  
  46. /*
  47.  *  some SAS/C specularities, change for other compilers!
  48.  */
  49. #ifdef __SASC
  50. extern struct Library *DOSBase; /* Library base pointer from startup code */
  51. extern struct Library *SysBase; /* Library base pointer from startup code */
  52.  
  53. // void chkabort(void) {}          /* disable Ctrl-C detect */
  54. // This one has been included in SAS/C 6.51 so remove the double slashes if
  55. // you use an earlier version.
  56.  
  57. #endif
  58.  
  59. /*
  60.  *  a string, which will be found by Version
  61.  */
  62. char version[] ="\0$VER: Request 2.03 (10/11/94) by Stefan Sticht and Goncalves A. Georges";
  63.  
  64. struct Library       *ReqToolsBase;
  65. struct IntuitionBase *IntuitionBase;
  66.  
  67. /*
  68.  *  dummy window, we have to open
  69.  */
  70. struct NewWindow dummywindow = {
  71.     0, 0,
  72.     1, 1,
  73.     (unsigned char)-1, (unsigned char)-1,
  74.     0l,
  75.     BORDERLESS | BACKDROP | SIMPLE_REFRESH,
  76.     NULL,
  77.     NULL,
  78.     NULL,
  79.     NULL,
  80.     NULL,
  81.     0, 0,
  82.     0, 0,
  83.     CUSTOMSCREEN
  84. };
  85.  
  86. #define TEMPLATE "TEXT/A,TITLE/K,GADS=GADGETS/K,C=CENTER/S,DEF=DEFAULT/K/N,NODEF=NODEFAULT/S,FLASH/S,PS=PUBSCREEN/K,DEFPS=DEFAULTPUBSCREEN/S,FRONTPS=FRONTPUBSCREEN/S"
  87. #define OPT_TEXT            0
  88. #define OPT_TITLE           1
  89. #define OPT_GADGETS         2
  90. #define OPT_CENTER          3
  91. #define OPT_DEFAULT         4
  92. #define OPT_NODEFAULT       5
  93. #define OPT_FLASH           6
  94. #define OPT_PUBSCREEN       7
  95. #define OPT_DEFPUBSCREEN    8
  96. #define OPT_FRONTPUBSCREEN  9
  97. #define OPT_COUNT           10
  98.  
  99. /*
  100.  *  this array will be filled by ReadArgs()
  101.  */
  102. long options[OPT_COUNT];
  103.  
  104. struct Screen *lockfrontpubscr(void)
  105. {
  106.     struct Screen *scr;
  107.     struct Screen *pubscr = NULL;
  108.     struct List *pslist;
  109.     struct PubScreenNode *psnode;
  110.     unsigned long lock;
  111.     unsigned short screentype;
  112.  
  113.     lock = LockIBase(0l);
  114.  
  115.     if (scr = IntuitionBase->FirstScreen) {
  116.  
  117.         screentype = scr->Flags & SCREENTYPE;
  118.  
  119.         UnlockIBase(lock);
  120.  
  121.         if (screentype == PUBLICSCREEN || screentype == WBENCHSCREEN) {
  122.  
  123.             if (pslist = LockPubScreenList()) {
  124.  
  125.                 for (psnode = (struct PubScreenNode *)pslist->lh_Head;
  126.                      psnode->psn_Node.ln_Succ && (psnode->psn_Screen != scr);
  127.                      psnode = (struct PubScreenNode *)psnode->psn_Node.ln_Succ);
  128.  
  129.                 if (psnode && (psnode->psn_Screen == scr) && !(psnode->psn_Flags & PSNF_PRIVATE)) {
  130.  
  131.                     pubscr = LockPubScreen(psnode->psn_Node.ln_Name);
  132.  
  133.                     }
  134.  
  135.                 UnlockPubScreenList();
  136.  
  137.                 }
  138.  
  139.             }
  140.  
  141.         }
  142.  
  143.     else UnlockIBase(lock);
  144.  
  145.     return(pubscr);
  146. }
  147.  
  148. char *Title;
  149. char *Gadgets;
  150. char *Text;
  151. long  Center = NULL;
  152. LONG    Default;
  153.  
  154. void _main(char *line)
  155. {
  156.     struct RDArgs *args;
  157.     struct Screen *scr = NULL;
  158.     struct Window *win;
  159.     char *screen = NULL;
  160.     long rc;
  161.     unsigned short defpubscreen = TRUE;
  162.  
  163.     if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37l))
  164.         && (ReqToolsBase = OpenLibrary("reqtools.library", 38L)))
  165.          {
  166.  
  167.         if (args = ReadArgs((UBYTE *)TEMPLATE, options, NULL))
  168.             {
  169.  
  170.             if (options[OPT_TITLE])
  171.               Title = (char *)options[OPT_TITLE];
  172.             
  173.             if (options[OPT_GADGETS])
  174.               Gadgets = (char *)options[OPT_GADGETS];
  175.             else
  176.               Gadgets = "Okay";
  177.             
  178.             if (options[OPT_TEXT])
  179.               Text = (char *)options[OPT_TEXT];
  180.             
  181.             if (options[OPT_CENTER])
  182.               Center = EZREQF_CENTERTEXT;
  183.             
  184.             if ( options[OPT_DEFAULT] )
  185.                Default = *( (LONG *)options[OPT_DEFAULT] );
  186.              else
  187.                Default = 1L;
  188.  
  189.             if ( options[OPT_NODEFAULT] )
  190.               Default = -1L;
  191.  
  192.             if (options[OPT_PUBSCREEN])
  193.               {
  194.                 screen = (char *)options[OPT_PUBSCREEN];
  195.                 defpubscreen = FALSE;
  196.               }
  197.             
  198.             if (options[OPT_DEFPUBSCREEN])
  199.               defpubscreen = TRUE;
  200.  
  201.             /*
  202.              *  try to lock a screen according to switches
  203.              */
  204.             if ((options[OPT_FRONTPUBSCREEN] && (scr = lockfrontpubscr())) ||
  205.                 (!scr && screen && *screen && (scr = LockPubScreen(screen))) ||
  206.                 (!scr && defpubscreen && (scr = LockPubScreen(NULL))))
  207.               {
  208.  
  209.                 dummywindow.Screen = scr;
  210.                 /*
  211.                  *  try to open visitor window
  212.                  */
  213.                 if(win = OpenWindow(&dummywindow))
  214.                 {
  215.                   if ( options[ OPT_FLASH ] )
  216.                     DisplayBeep( NULL );
  217.                   rc = rtEZRequestTags( Text, Gadgets, NULL, NULL,
  218.                     RT_Window,            (struct Window *) win,
  219.                     RT_Underscore,        '_',
  220.                     RTEZ_DefaultResponse, Default,
  221.                     RTEZ_ReqTitle,        Title,
  222.                     RTEZ_Flags,           Center,
  223.                     TAG_END);
  224.                 }
  225.                 /*
  226.                  *  don't forget closing the window
  227.                  */
  228.                 if (win) CloseWindow(win);
  229.                 /*
  230.                  *  now unlock the screen
  231.                  */
  232.                 UnlockPubScreen(NULL, scr);
  233.               }
  234.  
  235.             else
  236.               {
  237.                 /*
  238.                  * public screen not found
  239.                  */
  240.                 PutStr("Can't find or lock screen!\n");
  241.                 rc = 20l;
  242.               }
  243.  
  244.             }
  245.  
  246.         else
  247.           {
  248.             /*
  249.              * error parsing options
  250.              */
  251.             PutStr("wrong number of arguments\n");
  252.             rc = 40l;
  253.           }
  254.  
  255.         /*
  256.          *  free arguments and close the lib
  257.          */
  258.         FreeArgs(args);
  259.         CloseLibrary((struct Library *)IntuitionBase);
  260.         CloseLibrary((struct Library *)ReqToolsBase);
  261.  
  262.         }
  263.  
  264.     else
  265.       {
  266.         /*
  267.          *  we really need intuition lib
  268.          *
  269.          *  don't use PutStr() here, because dos.library could be < v36
  270.          */
  271.         Write(Output(), "Can't open intuition.library V37+ and/or reqtools.library V38+ !!!\n", 66l);
  272.         rc = 30l;
  273.       }
  274.     exit(rc);
  275. }
  276. //]
  277.